package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;

import java.util.Set;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {


    @Override
    public UserVO findUserByUsername(String username) {
        UserVO userVO = baseMapper.findUserByUsername(username);
        //
        Set<RoleVO> roleVOS  =baseMapper.findRolesByUid(userVO.getId());

        for (RoleVO roleVO : roleVOS) {
            Set<Permission> permissions = baseMapper.findPermssionsByRoleId(roleVO.getId());
            roleVO.setPermissions(permissions);
        }

        userVO.setRoles(roleVOS);
        return userVO;
    }
}
